class MachineCode(object):
    def __init__(self, x, n):
        self.x = x
        self.n = n

        self.domain_p = 2 ** (self.n - 1) - 1

    def domain(self):
        return -self.domain_p <= self.x <= self.domain_p

    def greater(self):
        return 0

    def less(self):
        return 0

    def print_code(self):
        if self.domain():
            if self.x >= 0:
                print(bin(self.greater()).replace("0b", "").zfill(self.n))
            else:
                print(bin(self.less()).replace("0b", "").zfill(self.n))
        else:
            print("Domain is false")


class OriginalCode(MachineCode):
    def __init__(self, x, n):
        super().__init__(x, n)

    def greater(self):
        return self.x

    def less(self):
        return 2 ** (self.n - 1) + abs(self.x)


class InverseCode(MachineCode):
    def __init__(self, x, n):
        super().__init__(x, n)

    def greater(self):
        return self.x

    def less(self):
        return 2 ** (self.n - 1) - 1 - abs(self.x)


class ComplementCode(MachineCode):
    def __init__(self, x, n):
        super().__init__(x, n)

    def greater(self):
        return self.x

    def less(self):
        return 2 ** self.n - abs(self.x)


if __name__ == "__main__":
    InverseCode(-127, 8).print_code()
